package queue;

import java.util.Random;

/**
 * @author wangzu
 * @date 2018/10/18
 */
public class App {

    public static void main(String[] args) {
        int opCount = 100000;

        Queue<Integer> queue;

        queue = new ArrayQueue<>();
        double time1 = testQueue(queue, opCount);
        System.out.println("ArrayQueue, time: " + time1);

        queue = new LoopQueue<>();
        double time2 = testQueue(queue, opCount);
        System.out.println("LoopQueue, time: " + time2);

        queue = new LinkedListQueue<>();
        double time3 = testQueue(queue, opCount);
        System.out.println("LinkedListQueue, time: " + time3);

    }

    private static double testQueue(Queue<Integer> q, int opCount) {

        long startTime = System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }

        long endTime = System.nanoTime();

        return (endTime - startTime) / 1000000000.0;
    }

}
